If Exists(Select 1 From sysobjects where name = 'fn_GetDotNetType')
    Drop Function dbo.fn_GetDotNetType
go
Create Function dbo.fn_GetDotNetType
(
	@name		sysname,
	@nullable	bit
)
returns sysname
As
Begin
	Declare @retorno	sysname
	Select	@retorno =	Case
							When	@name	= 'bigint'				Then 'Int64'
							When	@name	= 'binary'				Then 'object'
							When	@name	= 'bit'					Then 'bool'
							When	@name	= 'char'				Then 'string'
							When	@name	= 'datetime'			Then 'DateTime'
							When	@name	= 'float'				Then 'double'
							When	@name	= 'decimal'				Then 'decimal'
							When	@name	= 'numeric'				Then 'decimal'
							When	@name	= 'int'					Then 'Int32'
							When	@name	= 'nchar'				Then 'string'
							When	@name	= 'nvarchar'			Then 'string'
							When	@name	= 'smallint'			Then 'Int16'
							When	@name	= 'sql_variant'			Then 'object'
							When	@name	= 'text'				Then 'string'
							When	@name	= 'tinyint'				Then 'Int16'
							When	@name	= 'uniqueidentifier'	Then 'object'
							When	@name	= 'varbinary'			Then 'object'
							When	@name	= 'varchar'				Then 'string'
							When	@name	= 'xml'					Then 'string'
							When	@name	= 'money'				Then 'decimal'
							When	@name	= 'smallmoney'			Then 'decimal'
						End
	If @nullable = 1
		Select	@retorno =	@retorno + Case
											When	@name	= 'bigint'				Then '?'
											When	@name	= 'bit'					Then '?'
											When	@name	= 'datetime'			Then '?'
											When	@name	= 'float'				Then '?'
											When	@name	= 'int'					Then '?'
											When	@name	= 'smallint'			Then '?'
											When	@name	= 'tinyint'				Then '?'
											Else	''
										End
	Return @retorno
End

